/*************************************************
 * 描述: 
 *
 * File: styleditemdelegatefactory.cpp
 * Author: shizhixin@mozihealthcare.cn
 * Date: 2025-10-21
 * Update: 
 * ************************************************/
#include "styleditemdelegatefactory.h"


std::map<item_det, item_create_t> StyledItemDelegateFactory::m_items;

void StyledItemDelegateFactory::init(QObject* parent)
{
	m_items.clear();

	// // 注册下拉框委托
	// registerDelegate(ItemDelegateType::ComboBox,
	//                  [parent](const GridColumn &col, QObject *parentObj) -> QAbstractItemDelegate * {
	//                      auto delegate = new ComboBoxDelagate(parentObj);
	//                      delegate->setComboBoxItems(col.comboDataSource);
	//                      return delegate;
	//                  });
	//
	// // 注册弹出表格委托
	// registerDelegate(ItemDelegateType::TableComboBox,
	//                  [parent](const GridColumn &col, QObject *parentObj) -> QAbstractItemDelegate * {
	//                      // auto cfg = std::static_pointer_cast<PopupTableEditorConfig>(config);
	//                      auto delegate = new PopupTableDelegate(parentObj);
	//                      return delegate;
	//                  });
	//
	// // 注册日期时间委托
	// registerDelegate(ItemDelegateType::DateTime,
	//                  [parent](const GridColumn &col, QObject *parentObj) -> QAbstractItemDelegate * {
	//                      auto delegate = new DateTimeDelegate(col.format, parentObj);
	//                      return delegate;
	//                  });
	// registerDelegate(ItemDelegateType::Date,
	//                  [parent](const GridColumn &col,
	//                           QObject *parentObj) -> QAbstractItemDelegate * {
	//                      auto delegate = new DateDelegate(col.format, parentObj);
	//                      return delegate;
	//                  });
	//
	// registerDelegate(ItemDelegateType::CheckBox,
	//              [parent](const GridColumn &col,
	//                       QObject *parentObj) -> QAbstractItemDelegate * {
	//                  auto delegate = new CheckBoxDelegate(parentObj);
	//                  return delegate;
	//              });
}

void StyledItemDelegateFactory::registerDelegate(item_det type, item_create_t func)
{
	m_items[type] = func;
}

QAbstractItemDelegate* StyledItemDelegateFactory::createDelegate(const cxitable::GridColumnConfig& col, QObject* parent)
{
	auto type = col.style;
	auto it = m_items.find(type);
	if (it != m_items.end())
	{
		return it->second(col, parent);
	}
	return nullptr;
}